package com.restaurant.application.consumption.support;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;

public class OrderData implements PickableBean {

    public static final String FN_TIME = "time";
    public static final String FN_SHOPID = "shopID";
    public static final String FN_NUMBER = "number";
    public static final String FN_POSITION = "position";
    public static final String FN_TOTALPRICE = "totalPrice";
    public static final String FN_RECORDID = "recordId";
    public static final String FN_FACTPRICE = "factPrice";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_TIME,
            FN_SHOPID,
            FN_NUMBER,
            FN_POSITION,
            FN_TOTALPRICE,
            FN_RECORDID,
            FN_FACTPRICE);
    
    private Long time;
    private String shopID;
    private String number;
    private String position;
    private Double totalPrice;
    private Long recordId;
    private Double factPrice;

    public OrderData(Long time, String shopID, String number, String position, Double totalPrice, Long recordId, Double factPrice) {
        setTime(time);
        setShopID(shopID);
        setNumber(number);
        setPosition(position);
        setTotalPrice(totalPrice);
        setRecordId(recordId);
        setFactPrice(factPrice);
    }

    public OrderData() {
    }

    public OrderData duplicate() {
        OrderData result = new OrderData();
        result.time = this.time;
        result.shopID = this.shopID;
        result.number = this.number;
        result.position = this.position;
        result.totalPrice = this.totalPrice;
        result.recordId = this.recordId;
        result.factPrice = this.factPrice;
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public Long getTime() {
        return time;
    }

    public void setTime(Long value) {
        this.time = value;
    }

    public OrderData withTime(Long value) {
        setTime(value);
        return this;
    }

    public OrderData withTime(Long value, Long defaultValue) {
        setTime(value == null ? defaultValue : value);
        return this;
    }

    public String getShopID() {
        return shopID;
    }

    public void setShopID(String value) {
        this.shopID = value;
    }

    public OrderData withShopID(String value) {
        setShopID(value);
        return this;
    }

    public OrderData withShopID(String value, String defaultValue) {
        setShopID(value == null ? defaultValue : value);
        return this;
    }
    
    public String getNumber() {
        return number;
    }

    public void setNumber(String value) {
        this.number = value;
    }

    public OrderData withNumber(String value) {
        setNumber(value);
        return this;
    }

    public OrderData withNumber(String value, String defaultValue) {
        setNumber(value == null ? defaultValue : value);
        return this;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String value) {
        this.position = value;
    }

    public OrderData withPosition(String value) {
        setPosition(value);
        return this;
    }

    public OrderData withPosition(String value, String defaultValue) {
        setPosition(value == null ? defaultValue : value);
        return this;
    }

    public Double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Double value) {
        this.totalPrice = value;
    }

    public OrderData withTotalPrice(Double value) {
        setTotalPrice(value);
        return this;
    }

    public OrderData withTotalPrice(Double value, Double defaultValue) {
        setTotalPrice(value == null ? defaultValue : value);
        return this;
    }

    public Long getRecordId() {
        return recordId;
    }

    public void setRecordId(Long value) {
        this.recordId = value;
    }

    public OrderData withRecordId(Long value) {
        setRecordId(value);
        return this;
    }

    public OrderData withRecordId(Long value, Long defaultValue) {
        setRecordId(value == null ? defaultValue : value);
        return this;
    }
    
    public Double getFactPrice() {
        return factPrice;
    }

    public void setFactPrice(Double value) {
        this.factPrice = value;
    }

    public OrderData withFactPrice(Double value) {
        setFactPrice(value);
        return this;
    }

    public OrderData withFactPrice(Double value, Double defaultValue) {
        setFactPrice(value == null ? defaultValue : value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "time":
                return getTime();
            case "shopID":
                return getShopID();
            case "number":
                return getNumber();
            case "position":
                return getPosition();
            case "totalPrice":
                return getTotalPrice();
            case "recordId":
                return getRecordId();
            case "factPrice":
                return getFactPrice();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof OrderData)) return false;
        return signature().equals(((OrderData) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean OrderData has no signature defined, no hash code or equals possible.");
    }
}
